Skip to content

feature/jackson3 native (fixes #22294)#23071

Open
thorstenhirsch wants to merge 34 commits intoOpenAPITools:masterfrom
thorstenhirsch:feature/jackson3-native
Open

feature/jackson3 native (fixes #22294)#23071
thorstenhirsch wants to merge 34 commits intoOpenAPITools:masterfrom
thorstenhirsch:feature/jackson3-native

Conversation

@thorstenhirsch
Copy link
Contributor

@thorstenhirsch thorstenhirsch commented Feb 27, 2026

Add Jackson 3 support to java-native.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR solves a reported issue, reference it using GitHub's linking syntax (e.g., having "fixes #123" present in the PR description)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04) @lwlee2608 (2019/10) @martin-mfg (2023/08)


Summary by cubic

Adds opt‑in Jackson 3 support to the Java native client generator while keeping Jackson 2 as default. Fixes #22294. When enabled it requires Java 17+, improves RFC3339 date/time handling, validates option combos, and ships a native-jackson3 sample wired into CI (JDK 17/21).

  • New Features

    • Opt‑in useJackson3: dynamic imports via {{jacksonPackage}}, switch to JsonMapper with EnumFeature/DateTimeFeature, adopt SerializationContext, update RFC3339 module/Instant deserializer, better anyOf/oneOf, handle JacksonException, remove unused IOException, fix mapper.copy().
    • Build/CI: Java 17 source/target for Jackson 3; upgrade to Jackson 3.1.0; pin jackson-annotations 2.21; add java-native-jackson3 config and samples/client/petstore/java/native-jackson3; include sample in samples-java-client-jdk17 workflow; add JDK HttpClient test; enable JUnit 5 and useJUnitPlatform() in native/native-async Gradle builds.
    • Validation/docs/configs: fail on unsupported combinations (useJackson3 with openApiNullable, or with unsupported libraries); clarify support matrix (supported for native, and for restclient with useSpringBoot4=true); remove useJackson3 from resttemplate/webclient configs and refresh samples; fix duplicated method names in generated WithHttpInfo docs.
  • Migration

    • Default remains Jackson 2. To opt in for native, set additionalProperties.useJackson3=true and openApiNullable=false (requires Java 17+). For restclient, support requires useSpringBoot4=true.
    • useJackson3 is incompatible with openApiNullable and not supported for resttemplate or webclient; the generator now fails on these combinations.

Written for commit f45392e. Summary will update on new commits.

@thorstenhirsch thorstenhirsch marked this pull request as ready for review February 27, 2026 17:39
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 issues found across 304 files

Note: This PR contains a large number of files. cubic only reviews up to 75 files per PR, so some files may not have been reviewed.

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="modules/openapi-generator/src/main/resources/Java/libraries/native/pom.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/Java/libraries/native/pom.mustache:268">
P1: Potential compile failure: When useJackson3=true, jackson-databind-nullable dependency is excluded from POM, but pojo.mustache still generates JsonNullable type references if openApiNullable is enabled (default). This causes compilation errors due to missing import org.openapitools.jackson.nullable.JsonNullable.</violation>
</file>

<file name="samples/client/petstore/java/native-jackson3/build.gradle">

<violation number="1" location="samples/client/petstore/java/native-jackson3/build.gradle:87">
P2: JUnit 5 is incompletely configured - missing engine dependency and useJUnitPlatform()</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/Java/libraries/native/model.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/Java/libraries/native/model.mustache:50">
P0: Incorrect Jackson 3 annotation package imports. The `jackson-annotations` module deliberately kept `com.fasterxml.jackson.annotation.*` package in Jackson 3 for backward compatibility - only core modules moved to `tools.jackson.*`. Fix: annotation imports should remain as `com.fasterxml.jackson.annotation.*` in the useJackson3 section.</violation>
</file>

<file name="samples/client/petstore/java/native-jackson3/docs/DefaultApi.md">

<violation number="1" location="samples/client/petstore/java/native-jackson3/docs/DefaultApi.md:73">
P2: Documentation method signature contains extra 'fooGet' token, resulting in invalid Java syntax 'ApiResponse<FooGetDefaultResponse> fooGet fooGetWithHttpInfo()'. Should be 'ApiResponse<FooGetDefaultResponse> fooGetWithHttpInfo()'.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@thorstenhirsch
Copy link
Contributor Author

thorstenhirsch commented Mar 1, 2026

I'm not sure about the JUnit 5 changes in samples/client/... - here's what Claude Sonnet 4.6 says when asked for the reason of these changes:

The sample changes come from two of our template fixes that affect all native library samples, not just the Jackson 3 one:

  1. build.gradle.mustache — we added testRuntimeOnly "junit-jupiter-engine" and test { useJUnitPlatform() } to fix incomplete JUnit 5 configuration. This regenerated
    build.gradle in every native library sample (native-async, echo_api/java/native, etc.).
  2. api_doc.mustache — we removed the duplicate {{operationId}} token from WithHttpInfo method signatures. This regenerated all native library API docs (removing the
    spurious prefix like > fooGet fooGetWithHttpInfo() → > fooGetWithHttpInfo()).

Sounds reasonable to me. If you don't want them here, but in a separate PR instead, I will revert them here, of course.

@thorstenhirsch
Copy link
Contributor Author

Alright, please do another code review @cubic-dev-ai

@cubic-dev-ai
Copy link
Contributor

cubic-dev-ai bot commented Mar 1, 2026

Alright, please do another code review @cubic-dev-ai

@thorstenhirsch I have started the AI code review. It will take a few minutes to complete.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 issues found across 333 files

Note: This PR contains a large number of files. cubic only reviews up to 75 files per PR, so some files may not have been reviewed.

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="samples/client/petstore/java/native-jackson3/README.md">

<violation number="1" location="samples/client/petstore/java/native-jackson3/README.md:18">
P1: README incorrectly states Java 11+ requirement but Jackson 3 requires Java 17+. This documentation error will cause build/runtime failures for users following the instructions.</violation>
</file>

<file name="samples/client/petstore/java/native-jackson3/.travis.yml">

<violation number="1" location="samples/client/petstore/java/native-jackson3/.travis.yml:6">
P1: Travis CI uses JDK 11 (oraclejdk11) but Jackson 3.x requires Java 17+</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/Java/libraries/native/ApiClient.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/Java/libraries/native/ApiClient.mustache:4">
P1: JsonNullableModule is not registered when useJackson3 is enabled, breaking JsonNullable (de)serialization for models generated with openApiNullable=true</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@thorstenhirsch
Copy link
Contributor Author

Sorry, this PR is still not ready. The generated code contains wrong imports. I'm working on it.

@thorstenhirsch
Copy link
Contributor Author

Alright, I've fixed SerializerProvider/SerializationContext, ObjectMapper/JsonMapper issues and error handling with the new JacksonException. Now I could successfully generate a Java client with Jackson 3, all unit tests succeed. Also, I've made sure that Jackson 2 still works.

Now I guess it's finally time to start with human code reviews. And sorry @robinmarechal that I've asked you too early and wasted your time.

@wing328 wing328 added this to the 7.21.0 milestone Mar 4, 2026
@thorstenhirsch
Copy link
Contributor Author

Lots of getters and setters missing in modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenModel.java after I've merged master into this feature branch. Looks like I now need to respect useSpringBoot4, as well. Let me give it a shot ...

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 66 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="docs/generators/java.md">

<violation number="1" location="docs/generators/java.md:100">
P2: Documentation for useJackson3 with 'native' library is missing Java 17 requirement. Jackson 3 requires Java 17 but the documentation only mentions 'native' library requires Java 11+, misleading users who may attempt to use useJackson3 on Java 11-16.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@thorstenhirsch
Copy link
Contributor Author

Alright, this branch is now aligned with restclient's Jackson 3.1.0, unit tests and the integration test you mentioned succeed. @wing328

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="docs/generators/java-microprofile.md">

<violation number="1" location="docs/generators/java-microprofile.md:100">
P2: Documentation regression: The `useJackson3` option description removes the incompatibility warning for `openApiNullable`, but the generator code (`JavaClientCodegen.java`) still silently disables `openApiNullable` when both options are enabled. This creates a documentation-to-implementation contract mismatch where users expect the combination to work but won't get the expected nullable functionality in generated code.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 issues found across 31 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="samples/client/petstore/java/webclient-springBoot4-jackson3/build.gradle">

<violation number="1" location="samples/client/petstore/java/webclient-springBoot4-jackson3/build.gradle:131">
P1: The `webclient-springBoot4-jackson3` sample build.gradle replaces Jackson 3 dependencies (`tools.jackson.*:3.1.0`) with Jackson 2 dependencies (`com.fasterxml.jackson.*:2.21.1`), which breaks the sample's purpose of validating Jackson 3 compatibility. Other jackson3 samples like `restclient-springBoot4-jackson3` correctly use Jackson 3 coordinates.</violation>
</file>

<file name="samples/client/petstore/java/resttemplate-springBoot4-jackson3/build.gradle">

<violation number="1" location="samples/client/petstore/java/resttemplate-springBoot4-jackson3/build.gradle:100">
P1: Jackson 3 sample now depends on Jackson 2 artifacts, silently breaking Jackson 3 support validation coverage.</violation>
</file>

<file name="samples/client/petstore/java/webclient-springBoot4-jackson3/src/main/java/org/openapitools/client/ApiClient.java">

<violation number="1" location="samples/client/petstore/java/webclient-springBoot4-jackson3/src/main/java/org/openapitools/client/ApiClient.java:19">
P1: The jackson3 sample has been regenerated with Jackson 2 APIs instead of Jackson 3 APIs. The code changed from using `tools.jackson.*` package classes (JacksonJsonEncoder/JacksonJsonDecoder, JsonMapper) to `com.fasterxml.jackson.*` package classes (Jackson2JsonEncoder/Jackson2JsonDecoder, ObjectMapper). This invalidates the sample's purpose of testing Jackson 3.x compatibility with Spring Boot 4, as CI would falsely report Jackson 3 works when it's not actually being tested.</violation>
</file>

<file name="samples/client/petstore/java/resttemplate-springBoot4-jackson3/pom.xml">

<violation number="1" location="samples/client/petstore/java/resttemplate-springBoot4-jackson3/pom.xml:234">
P1: Sample POM 'resttemplate-springBoot4-jackson3' has been downgraded from Jackson 3 (3.1.0) to Jackson 2 (2.21.1), losing the purpose of validating Jackson 3 compatibility. Other jackson3 samples (native-jackson3, restclient-springBoot4-jackson3) correctly use Jackson 3 dependencies.</violation>
</file>

<file name="samples/client/petstore/java/resttemplate-springBoot4-jackson3/src/main/java/org/openapitools/client/RFC3339DateFormat.java">

<violation number="1" location="samples/client/petstore/java/resttemplate-springBoot4-jackson3/src/main/java/org/openapitools/client/RFC3339DateFormat.java:22">
P1: Jackson 3 sample uses incorrect namespace and Jackson 2 dependencies instead of Jackson 3. The code changed from tools.jackson (correct Jackson 3 namespace) to com.fasterxml.jackson (Jackson 2 namespace), while dependencies also reference Jackson 2.21.1. This means the 'jackson3' sample doesn't actually use Jackson 3.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@thorstenhirsch
Copy link
Contributor Author

thorstenhirsch commented Mar 12, 2026

Feels like going 2 steps back... why do I need to cope with resttemplate and webclient reverting from Jackson 3 to Jackson 2 here? I've synced my forked repo and rebased my branch - but with no effect. Was everything up-to-date already? Seems like this is the point when I got lost regarding resttemplate/webclient.

@thorstenhirsch thorstenhirsch force-pushed the feature/jackson3-native branch from ac30f57 to fc5b350 Compare March 12, 2026 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[REQ] Jackson3 support for java libraries

3 participants